import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import path from 'path';


// import Layouts from 'vite-plugin-vue-layouts';
export default defineConfig(({ mode }) => {
	const env = loadEnv(mode, process.cwd())
	console.log(env, 'env');
	return {
		base: './',
		plugins: [
			vue(),
			AutoImport({
				// 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
				imports: ['vue'],
			}),
			Components({
				// 指定自动导入的组件位置，默认是 src/components
				// dirs: ['src/components'],
			}),
		],
		resolve: {
			alias: {
				"@": path.resolve(__dirname, "src")
			}
		},
		server: {
			host: true,
			port: 8888,
			proxy: {
				[env.VITE_API_URL]: {
					target: env.VITE_BASE_URL,
					changeOrigin: true,
					rewrite: path => path.replace(new RegExp(`^${env.VITE_API_URL}`), '')
				},
			}
		}
	}
});
